package com.whk.push;

import java.lang.ref.SoftReference;
import java.util.Queue;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;

public class PushBuilder {

    private PushCall call;
    private Queue<SoftReference<PushMessage>> queue ;
    private ExecutorService executor;
    private PushLogger log;
    private int resultSize;

    /**
     * 设置logger
     * @param log
     * @return
     */
    public PushBuilder configLogger(PushLogger log){
        this.log = log;
        return this;
    }

    /**
     * 设置回调函数
     * @param call 回调函数
     * @return
     */
    public PushBuilder configCallable(PushCall call){
        this.call = call;
        return this;
    }

    /**
     * 设置线程池（只支持单例）
     * @param executor
     * @return
     */
    public PushBuilder configExecutor(ExecutorService executor){
        this.executor = executor;
        return this;
    }

    /**
     * 设置发送消息队列
     * @param queue
     * @return
     */
    public PushBuilder configQueue(Queue<SoftReference<PushMessage>> queue){
        this.queue = queue;
        return this;
    }

    /**
     * 设置结果保留长度
     * @param resultSize
     * @return
     */
    public PushBuilder configResultSize(int resultSize){
        this.resultSize = resultSize;
        return this;
    }

    public PushUtil build(){
        return new PushUtil(queue, executor, log, call, resultSize);
    }

}
